#include <cjsonpare.h>
#include <cjsonerror.h>
//#include <cjsonvalues.h>
#include <cjsonvalue.h>

CJsonPare::CJsonPare()
{
  name  = NULL;
  value = NULL;
}

CJsonPare::~CJsonPare()
{
  if (name)
  {
    delete name;
  }
  if (value)
  {
    delete ((CJsonValue*)value);
  }
}

CJsonPare::CJsonPare(CJsonName *name, CJsonValue *value)
{
  if (!name || !value)
  {
    throw CJsonError(INVALID_PARAM);
  }
  this->name = name;
  this->value = value;
}

jstring CJsonPare::ToString()
{
  return name->ToString() + J(":") + value->ToString();
}

void CJsonPare::AddName(CJsonName *name)
{
  this->name = name;
}

void CJsonPare::AddValue(CJsonValue *value)
{
  this->value = value;
}

bool CJsonPare::CompareName(jstring * name) const
{
  return ( (*this->name) ==  name );
}

bool CJsonPare::CompareName(jstring & name) const
{
  return ( (*this->name) == name );
}

jstring CJsonPare::GetNameString() const
{
  return name->GetNameString();
}

jchar const * const CJsonPare::GetNameCString() const
{
  return name->GetNameCString();
}

CJsonValue * CJsonPare::GetValue() const
{
  return value;
}

